home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jaz_clib.arc / JZCPYFIL.C < prev    next >
Text File  |  1989-04-09  |  2KB  |  97 lines

  1.  
  2. /*
  3. ┌────────────────────────────────────────────────────────────────────────────┐
  4. │jzcpyfil.c                                     │
  5. │Copy a file (wild cards are ok)                         │
  6. │                                         │
  7. │synopsis                                     │
  8. │  werr = jzcpyfil("\\jaz\\*.*","a:\");                                      │
  9. │                                         │
  10. └────────────────────────────────────────────────────────────────────────────┘
  11. */
  12.  
  13. #include <jaz.h>
  14. #include <jzdirect.h>
  15.  
  16. #define SIZE 32767
  17.  
  18. jzcpyfil(fsource,fdestin)
  19. char *fsource;
  20. char *fdestin;
  21. {
  22.   int wsource,wdestin;
  23.   int wnum;
  24.   TDIR wdir;
  25.   int werr,wpos;
  26.   int w;
  27.   char wspath[65],wdpath[65];        /* source and destin path names */
  28.   char wtemp[65];
  29.   char *wbuf,*malloc();
  30.  
  31.   if ( (wbuf = malloc(SIZE)) == 0 ) {
  32.     printf("\Out of memory for copy, Aborting...");
  33.     exit(255);
  34.   }
  35.  
  36.   strcpy(wspath,fsource);
  37.   strcpy(wdpath,fdestin);
  38.  
  39.   for (w = strlen(wspath) - 1 ; w >= 0 ; w --)    /* parse out path */
  40.     if (wspath[w] == '\\')
  41.       break;
  42.  
  43.   if (w >= 0)
  44.     wspath[w+1] = 0;            /* hold only the path */
  45.   else
  46.     *wspath = 0;            /* Null path string */
  47.  
  48.   w = strlen(wdpath) - 1;
  49.  
  50.   if (index("?*:",*(wdpath+w)) != -1 ) {
  51.     for ( ; w >= 0 ; w --)
  52.       if ((index("\\:",*(wdpath+w))) != -1)
  53.     break;
  54.     *(wdpath+w+1) = 0;
  55.   }
  56.   else
  57.     strcat(wdpath,"\\");
  58.  
  59.   #if DEBUG
  60.     printf("\nsource: %s",wspath);
  61.     printf("\ndestin: %s",wdpath);
  62.   #endif
  63.                /**
  64.             ** Here's where we search the directory
  65.             **/
  66.  
  67.   werr = jzfndfst(fsource,32,&wdir);    /* find first matching file */
  68.  
  69.   if (werr == 0)            /* perform directory search   */
  70.     do {
  71.       strcpy(wtemp,wspath);        /* get source path into wtemp */
  72.       strcat(wtemp,wdir.name);        /* get full source path name  */
  73.       wsource = jzopnfil(wtemp,0);    /* open for read only  */
  74.       strcpy(wtemp,wdpath);        /* get destin path into wtemp */
  75.       strcat(wtemp,wdir.name);        /* get full destin path name  */
  76.       wdestin = jzcrtfil(wtemp,0);    /* create file normal attribute */
  77.       printf("\n%s",wdir.name);
  78.  
  79.                /**
  80.             ** Here's where we copy the file.
  81.             **/
  82.  
  83.       do {
  84.     wnum = jzredfil(wsource,wbuf,SIZE);    /* request SIZE bytes to read */
  85.     if (wnum)
  86.       jzwrtfil(wdestin,wbuf,wnum);        /* write only num read */
  87.       } while (wnum);
  88.  
  89.       jzclsfil(wdestin);
  90.       jzclsfil(wsource);
  91.  
  92.       werr = jzfndnxt(&wdir);            /* get next item */
  93.     } while (werr == 0);
  94.   else
  95.     printf("\Not Found");
  96. }
  97.